package com.lcz.mobilesafe.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lcz.mobilesafe.R;
import com.lcz.mobilesafe.activity.BaseApplication;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hp on 2017/3/2.
 */

public class SettingItemView extends RelativeLayout {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_des)
    TextView tvDes;
    @BindView(R.id.cb_status)
    CheckBox cbStatus;
    private String NAMESPACE;
    private String title;
    private String desc_on;
    private String desc_off;

    public SettingItemView(Context context) {
        super(context);
        initView();
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        //获取属性
        NAMESPACE = "http://schemas.android.com/apk/res/com.lcz.mobilesafe";
        title = attrs.getAttributeValue(NAMESPACE, "title");
        desc_on = attrs.getAttributeValue(NAMESPACE, "desc_on");
        desc_off = attrs.getAttributeValue(NAMESPACE, "desc_off");
        initView();
    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    /*初始化布局*/
    private void initView() {
        View view = View.inflate(BaseApplication.getApplication(), R.layout.view_setting_item, this);
        ButterKnife.bind(view);
        setTitle(title);//设置标题
    }

    /*设置标题*/
    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    /*设置描述*/
    public void setDes(String des) {
        tvDes.setText(des);
    }

    /*返回勾选状态*/
    public boolean isCheck() {
        return cbStatus.isChecked();
    }

    public void setChecked(boolean checked) {
        cbStatus.setChecked(checked);
        if (checked) {
            setDes(desc_on);
        } else {
            setDes(desc_off);
        }
    }
}
